﻿using MediatR;
using System.CJL.API.Application.Command.ProcessCommand;
using System.CJL.Domain;
using System.CJL.Infrstructre.Interface;

namespace System.CJL.API.Application.CommandHanlder.ProcessCommandHanler
{
    /// <summary>
    /// 工序添加
    /// </summary>
    public class ProcessAddCommandHandler : IRequestHandler<ProcessAddCommand, int>
    {
        IProcessRepository _repository;
        /// <summary>
        /// 构造函数
        /// </summary>
        public ProcessAddCommandHandler(IProcessRepository repository)
        {
            _repository=repository;
        }
        /// <summary>
        /// 工序添加
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<int> Handle(ProcessAddCommand request, CancellationToken cancellationToken)
        {
            return await _repository.Addasync(new Process
            {
                ProcessNumebring=request.ProcessNumebring,
                ProcessName = request.ProcessName,
                ProcessStatus = request.ProcessStatus,
                ProcessIllustrate = request.ProcessIllustrate,
                ProcessReamrk = request.ProcessReamrk,
                ProcessDate = request.ProcessDate.ToUniversalTime(),
                IsDelete = false,
                AddName = request.AddName,
                AddTime = DateTime.Now.ToUniversalTime()
            });
        }
    }
}
